updating oE db_open

db_open

include eds.e 
namespace eds 
public function db_open(sequence path, integer lock_method = DB_LOCK_NO) 

opens an existing Euphoria database.

Parameters:
  1. path : a sequence, the path to the file containing the database
  2. lock_method : an integer specifying which sort of access can be granted to the database. The types of lock that you can use are:
    1. DB_LOCK_NO : (no lock) -- The default
    2. DB_LOCK_SHARED : (shared lock for read-only access)
    3. DB_LOCK_EXCLUSIVE : (for read and write access).
Returns:

An integer, status code, either DB_OK if creation successful or anything else on an error.

The return codes are:

public constant 
    DB_OK = 0          -- success 
    DB_OPEN_FAIL = -1  -- could not open the file 
    DB_LOCK_FAIL = -3  -- could not lock the file in the 
                       -- manner requested 
Comments:

DB_LOCK_SHARED is only supported on Unix platforms. It allows you to read the database, but not write anything to it. If you request DB_LOCK_SHARED on Windows it will be treated as if you had asked for DB_LOCK_EXCLUSIVE.

If the lock fails, your program should wait a few seconds and try again. Another process might be currently accessing the database.

Example 1:
tries = 0 
while 1 do 
    err = db_open("mydata", DB_LOCK_SHARED) 
    if err = DB_OK then 
        exit 
    elsif err = DB_LOCK_FAIL then 
        tries += 1 
        if tries > 10 then 
            puts(2, "too many tries, giving up\n") 
            abort(1) 
        else 
            sleep(5) 
        end if 
    else 
        puts(2, "Couldn't open the database!\n") 
        abort(1) 
    end if 
end while 
See Also:

db_create, db_select

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu